package com.yby6.web.controller.system;

import java.util.List;

import com.yby6.common.core.controller.BaseController;
import com.yby6.common.utils.poi.ExcelUtil;
import com.yby6.system.service.ISysDictTypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.yby6.common.core.AjaxResult;
import com.yby6.common.core.domain.SysDictType;
import com.yby6.common.core.page.TableDataInfo;

/**
 * 字典类型Controller
 *
 * @author yangbuyi
 * @date 2021-06-06
 */
@RestController
@RequestMapping("/system/type")
public class SysDictTypeController extends BaseController {
    @Autowired
    private ISysDictTypeService sysDictTypeService;

    /**
     * 查询字典类型列表
     */
    @GetMapping("/list")
    public TableDataInfo list(SysDictType sysDictType) {
        startPage();
        List<SysDictType> list = sysDictTypeService.selectSysDictTypeList(sysDictType);
        return getDataTable(list);
    }

    /**
     * 同步字典数据
     * @return
     */
    @PostMapping("/synchronizedDict")
    public AjaxResult synchronizedDict(){
        return toAjax(sysDictTypeService.synchronizedDict());
    }

    /**
     * 导出字典类型列表
     */
    @GetMapping("/export")
    public AjaxResult export(SysDictType sysDictType) {
        List<SysDictType> list = sysDictTypeService.selectSysDictTypeList(sysDictType);
        ExcelUtil<SysDictType> util = new ExcelUtil<SysDictType>(SysDictType.class);
        return util.exportExcel(list, "字典类型数据");
    }

    /**
     * 获取字典类型详细信息
     */
    @GetMapping(value = "/{dictId}")
    public AjaxResult getInfo(@PathVariable("dictId") Long dictId) {
        return AjaxResult.success(sysDictTypeService.selectSysDictTypeById(dictId));
    }


    /**
     * 新增字典类型
     */
    @PostMapping
    public AjaxResult add(@RequestBody SysDictType sysDictType) {
        return toAjax(sysDictTypeService.insertSysDictType(sysDictType));
    }

    /**
     * 修改字典类型
     */
    @PutMapping
    public AjaxResult edit(@RequestBody SysDictType sysDictType) {
        return toAjax(sysDictTypeService.updateSysDictType(sysDictType));
    }

    /**
     * 删除字典类型
     */
    @DeleteMapping("/{dictIds}")
    public AjaxResult remove(@PathVariable Long[] dictIds) {
        return toAjax(sysDictTypeService.deleteSysDictTypeByIds(dictIds));
    }
}
